home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
-
- class Coroutine:
- '''A simple message-passing coroutine implementation.
- \tNot thread- or signal-safe.
- \tUsage:
- \t\tdef my_iter (plexer, args):
- \t\t\tsome_async_task (..., callback=plexer.send (tokens))
- \t\t\tyield None
- \t\t\ttokens, (data, ) = plexer.receive ()
- \t\t\t...
- \t\tCoroutine (my_iter, args).begin ()
- \t'''
-
- def __init__(self, iter, *args):
- self._continuation = iter(self, *args)
- self._executing = False
-
-
- def _resume(self):
- if not self._executing:
- self._executing = True
-
- try:
- self._continuation.next()
- while self._data:
- self._continuation.next()
- except StopIteration:
- pass
- finally:
- self._executing = False
-
-
-
-
- def clear(self):
- self._data = []
-
-
- def begin(self):
- self.clear()
- self._resume()
-
-
- def send(self, *tokens):
-
- def callback(*args):
- self._data.append((tokens, args))
- self._resume()
-
- return callback
-
-
- def receive(self):
- return self._data.pop(0)
-
-
-